<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Welcome to CodeIgniter</title>
<style>
	#flash_message {
		color: red;
	}
	.error {
		color: red;
	}
	#reply_status {
		color: red;
	}
	#reply_status a{
		color: red;
	}
</style>
<script>
	function add_reply(id, author)
	{
		document.getElementsByName('parent')[0].value = id;
		document.getElementsByName('author')[0].focus();
		document.getElementById('reply_status').innerHTML = ' <回复' + author + '>';
		document.getElementById('reply_status').innerHTML += ' <a href="javascript:void(0)" onclick="cancel_reply()">[取消回复]';
		// document.getElementsByName('content')[0].value = '@' + author + ': ';
	}
	function cancel_reply()
	{
		document.getElementsByName('parent')[0].value = 0;
		document.getElementById('reply_status').innerHTML = '';
		document.getElementsByName('author')[0].focus();
	}
</script>		
</head>
<body>
<h1><?=anchor('post', 'back to add content');?>&nbsp;&nbsp;<?=anchor('post/post_list', 'post list');?></h1>
<? foreach ($post as $loop): ?>
<p>title: <a href="<?=site_url();?>/post/post_list/<?=$loop->id?>"><?=$loop->title?></a></p>
<p>content:<br /><?=$loop->content?></p>
<p>author: <?=$loop->author?></p>

<? if ($show_comments): ?>
<hr />
	comments:<br />
	<? foreach ($post_comments as $comment): ?>
	<p>
	<? //if (!empty(trim($comment->site))): ?>
	<? if (!empty($comment->site) && $comment->site != 'http://'): ?>	
	<a href="<?=$comment->site?>" target="_blank"><?=$comment->author?></a>
	<? else: ?>
	<?=$comment->author?>
	<? endif; ?>	
		 said: <a href="javascript:void(0)" onclick="add_reply(<?=$comment->id?>, '<?=$comment->author?>');return false;">[reply]</a><br /><?=$comment->content?>
	<?
		if (isset($comment_reply[$comment->id]) AND is_array($comment_reply[$comment->id]))
		{
			foreach ($comment_reply[$comment->id] as $reply)
			{
				if (!empty($reply['site']) && $reply['site'] != 'http://')
				{
					echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;' . '<a href="' . $reply['site'] . '" target="_blank">' .$reply['author'] . '</a>: ' . $reply['content'];	
				}
				else
				{
					echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;' . $reply['author'] . ': ' . $reply['content'];	
				}	
			}
		}
	?>
	<? endforeach; ?>
	</p>
<hr />
	leave your comments:<br />
	<? if ($this->session->flashdata('flash_message')): ?>	
	<span id="flash_message"><p><?=$this->session->flashdata('flash_message');?></p></span>
	<script>
		setTimeout(function(){document.getElementById("flash_message").style.display = 'none';}, 2000);
	</script>
	<? endif; ?>

	<?=validation_errors('<div clar">', '</div>');?>
	<?=form_open('post/post_list/' . $loop->id);?>
	<?=form_hidden('post_id', $loop->id)?>
	<?=form_hidden('parent', set_value('parent', 0))?>
	<p>Your name: <?=form_input('author', set_value('author'))?></p>
	<p>Your Site: <?=form_input('site', set_value('site'))?></p>
	<p>comments:<span id="reply_status"></span><br/><?=form_textarea('content', set_value('content'))?></p>
	<?=form_submit('', 'Submit Your Comment!');?>
<? endif; ?>

<hr />
<? endforeach; ?>

<p>Page rendered in {elapsed_time} seconds</p>

</body>
</html>